package com.derbysoft.lowcostadapter.commons.redis.utils;

import com.derbysoft.lowcostadapter.commons.model.RateCache;
import com.derbysoft.lowcostadapter.commons.model.RoomOccupancy;
import com.derbysoft.lowcostadapter.commons.model.RoomStay;
import com.derbysoft.lowcostadapter.commons.redis.service.RedisSerializable;

public abstract class RedisSerializableUtils {

    public static RedisSerializable of(String key, String field, String value) {
        if (key.startsWith(RoomOccupancy.PREFIX + KeyValueHelper.SEPARATOR)) {
            return RoomOccupancy.of(key, field, value);
        }
        if (key.startsWith(RateCache.PREFIX + KeyValueHelper.SEPARATOR)) {
            return RateCache.of(key, field, value);
        }
        if (key.startsWith(RoomStay.PREFIX + KeyValueHelper.SEPARATOR)) {
            return RoomStay.of(key, field, value);
        }
        throw new UnsupportedOperationException("unsupported redis serializable[" + key + "]");
    }

}
